﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Markup;

namespace SmartRoomFinder.Helpers
{
    #region
    public class BooleanToVisibilityConverter:MarkupExtension,IValueConverter
    {
       private BooleanToVisibilityConverter converter;
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return converter ?? (converter = new BooleanToVisibilityConverter());
        }

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return Binding.DoNothing; 
            }
            if (bool.Parse(value.ToString()))
            {
                return Visibility.Hidden;
            }
            else
            {
                return Visibility.Visible;  
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return Binding.DoNothing;
        }
    }
    public class InverseBooleanToVisibilityConverter : MarkupExtension, IValueConverter
   {
        private InverseBooleanToVisibilityConverter converter;
       public override object ProvideValue(IServiceProvider serviceProvider)
       {
           return converter ?? (converter = new InverseBooleanToVisibilityConverter());
       }

       public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           if (value == null)
           {
               return Binding.DoNothing;
           }
           if (bool.Parse(value.ToString()))
           {
               return Visibility.Visible;
           }
           else
           {
               if (parameter!=null&&parameter.ToString() == "Collapsed")
               {
                   return Visibility.Collapsed;
               }
               return Visibility.Hidden;
           }
       }

       public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
       {
           return Binding.DoNothing;
       }
   }


    #endregion
}
